package com.lighting.smssystem.model;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.lighting.smssystem.model.vo.CompanyForm;
import com.lighting.smssystem.utils.Long2StringConvert;
import com.lighting.smssystem.utils.SnowflakeIdWorker;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * Author LeeMaster
 * create table company_tbl (
 *   company_id bigint primary key auto_increment,
 *   company_name varchar(255) not null ,
 *   company_legal varchar(255) not null comment '公司法人',
 *   company_province varchar(255) not null comment '公司省份',
 *   company_city varchar(255) not null comment '公司市区',
 *   company_type varchar(255) not null comment '公司类型',
 *   company_tel varchar(255) not null comment '公司公式电话',
 *   company_other_tel varchar(255) not null default '-' comment '其他的电话',
 *   company_address varchar(255) not null default '-' comment '公司地址',
 *   company_website varchar(255) not null default '-' comment '公司网址',
 *   company_mail varchar(255) not null default '-' comment '公司邮箱',
 *   company_range text not null comment '公司经营范围',
 *   update_at timestamp not null default current_timestamp,
 *   create_at timestamp not null default current_timestamp
 * );
 */
@Data
@TableName("company_tbl")
@NoArgsConstructor
public class Company {

    public Company(CompanyForm form) {
        this.companyId = SnowflakeIdWorker.next();
        this.companyName = form.getCompanyName();
        this.companyLegal = form.getCompanyLegal();
        this.companyProvince = form.getCompanyProvince();
        this.companyCity = form.getCompanyCity();
        this.companyType = form.getCompanyType();
        this.companyTel = form.getCompanyTel();
        this.companyOtherTel = form.getCompanyOtherTel();
        this.companyAddress = form.getCompanyAddress();
        this.companyWebsite = form.getCompanyWebsite();
        this.companyMail = form.getCompanyMail();
        if (StringUtils.isEmpty(form.getCompanyRange())) {
            this.companyRange = "-";
        } else {
            this.companyRange = form.getCompanyRange();
        }

    }

    public static Company generateCompany(CompanyForm form){
        Company company = new Company(form);
        company.setCompanyId(form.getCompanyId());
        company.setUpdateAt(new Date());
        return company;
    }

    @JsonSerialize(using = Long2StringConvert.class)
    @TableId("company_id")
    private Long companyId;

    private String companyName;

    private String companyLegal;

    private String companyProvince;

    private String companyCity;

    private String companyType;

    private String companyTel;

    private String companyOtherTel;

    private String companyAddress;

    private String companyWebsite;

    private String companyMail;

    private String companyRange;

    private Date updateAt;

    private Date createAt;
}
